Methods and apparatus for data compression

ABSTRACT

The invention provides a plurality of compression schemes that provide improved compression ratios. An exemplary embodiment compresses each pixel by one of a plurality of different entropy-based compression schemes based upon a probability cost analysis. Another exemplary embodiment compresses each pixel based on a hybrid context formed using a plurality of compression schemes for improved probability determination, and thus improved entropy encoding.

CROSS-REFERENCE TO RELATED APPLICATIONS

[0001] This application is a continuation of U.S. application Ser. No.10/198,505, filed 18 Jul. 2002, now U.S. Pat. No. ______, which is acontinuation of application Ser. No. 09/249,729, filed 11 Feb. 1999, nowU.S. Pat. No. 6,449,393, which is a division of U.S. application Ser.No. 08/878,651, filed 19 Jun. 1997, now U.S. Pat. No. 5,970,174.

FIELD OF THE INVENTION

[0002] This invention relates to the field of compression anddecompression of data.

BACKGROUND ART

[0003] Information is represented in a computer system by binary data inthe form of 1s and 0s. This binary data is often maintained in a datastorage device. In a computer system, data storage is a limitedresource. To more efficiently use data storage resources, data is oftencompressed prior to storage so that less storage area is required. Whenthe data is retrieved, it is decompressed for use. The need forcompression can be demonstrated by describing the way that images arerepresented in a computer system, the transformation of such images intoa form suitable for printing, and the storage problems associated withsuch images. This discussion is followed by descriptions of compressiontechniques and prior art approaches to compression.

[0004] If a person were to look closely at a television screen, computerdisplay, magazine page, etc., he would see that an image is made up ofhundreds or thousands of tiny dots, where each dot is a different color.These dots are known as picture elements, or “pixels,” when they are ona computer display and as dots when printed on a page. The color of eachpixel is represented by a number value. To store an image in a computermemory, the number value of each pixel of the picture is stored. Thenumber value typically represents the color and intensity of the pixel.

[0005] The accuracy with which a document can be reproduced is dependenton the “resolution” of the pixels that make up the document. Theresolution of a pixel is determined by the range of the number valueused to describe that pixel. The range of the number value is limited bythe number of “bits” in the memory available to describe each pixel (abit is a binary number having a value of 1 or 0). The greater the numberof bits available per pixel, the greater the resolution of the document.For example, when only one bit per pixel is available for storage, onlytwo values are available for the pixel. If two bits are available, fourlevels of color or intensity are available. While greater resolution isdesirable, it can lead to greater use of data storage. For example, ifeach pixel is represented by a 32-bit binary number, 320,000 bits ofinformation would be required to represent a 100×100 pixel image. Suchinformation is stored in what is referred to as a “Frame Buffer” or grayarray (“G array”).

[0006] A black and white printer has resolution of only one bit perpixel or dot. That is, the printer is only capable of printing a blackdot at a location or of leaving the location blank. When an image is tobe printed on a black and white printer, the image must be transformedso that its bit resolution matches the bit resolution of the printer.This transformation is known as “thresholding” and consists ofdetermining, for each pixel in the source image, whether the dot to beprinted at the corresponding location on the printed page is to be blackor white.

[0007] Although the printer can only do black and white printing, aprinted image can appear to have many different shades of gray dependingon the pattern of black and white dots. When every other dot is black,for example, the resulting printed image will appear gray, because thehuman eye blends the tiny dots together. Many printers are capable ofprinting 600 dots per inch in the horizontal and vertical directions.Because of the large number of tiny dots, other shades of gray can besimulated by the relative percentage of black and white dots in anyregion. The more black dots in a region, the darker that region appears.

[0008] As noted above, when thresholding, a decision is made for eachpixel, based on its original color in the source image, of whether toprint a black or white dot on the page for that pixel. Consider athresholding scheme where each pixel in the stored gray-scale image maybe represented by 8 bits, for example, giving 256 (2⁸) possible values.One thresholding method that does not produce very realistic images isto assign a black value to all image pixels with a value of 128 (out of256) or above, and a white value to all image pixels with a value of 127or below. Using thresholding, an entire multi-bit depth frame buffer canbe compressed into a one bit per pixel buffer. However, the resultingimage is “aliased” (appears like steps or contains jagged edges) anddoes not approximate the original image. To produce better images, athreshold matrix is generated and used to determine the thresholdedvalue of an image pixel.

[0009] A threshold matrix uses different threshold values for an imagepixel, depending on the address of the image pixel in the array. Thus,each cell of the frame buffer corresponds to a threshold matrix cellwhich has an independent threshold level. The threshold matrix need notbe the same size and is often smaller than the G array. For example, atone location, an image pixel may be thresholded to black if its value is128 or above, while an image pixel at another location may be black onlyif its value is 225 or higher. The result of applying the thresholdmatrix is an array of Is and 0s that could be printed to represent theoriginal continuous tone image.

[0010]FIG. 1A depicts a frame buffer (G array), with indices i and j(G_([i][j])). FIG. 1B depicts a threshold matrix (T array), with indicesi′ and j′ (T_([i′][j′])). FIG. 1C depicts the resulting output or pixelarray (P array) with i rows and j columns (P_([i][j])). Thus, forexample, if the pixel maintains a value of 123 (G₁₁ of FIG. 1A) and thethreshold level is 128 (T₁₁ of FIG. 1B), the resulting value is 0 (P₁₁of FIG. 1C) due to the fact that the pixel value is less than thethreshold level. Hence the resulting pixel array is created bythresholding the G array as follows:${{P\lbrack i\rbrack}\lbrack j\rbrack} = \left\{ \begin{matrix}{{1\quad {if}\quad {{G\lbrack i\rbrack}\lbrack j\rbrack}} \geq {{T\left\lbrack i^{\prime} \right\rbrack}\left\lbrack j^{\prime} \right\rbrack}} \\{0\quad {otherwise}}\end{matrix} \right.$

[0011] where G[i][j] is an array of the same dimensions as P but takeson many values, typically 0,1, . . . ,255. T[i′][j′] is a thresholdarray, a matrix of dimension n threshold rows by m threshold columns andtaking on values in a range like G, typically 1,2, . . . ,255. For thethresholding (i′,j′) is a function of (i,j) typically:

[0012] i′=i modulo n

[0013] j′=j modulo m

[0014] where modulo means the remainder after division.

[0015] After this thresholding step, the entire page can be representedin a memory of 1s and 0s by the same number of bits as there are dots onthe page. Even at 1 bit per dot, the amount of memory required can besubstantial. For a page that is 8.5 by 11 inches and has a resolution of600 dots per inch (dpi), the amount of memory needed is approximately4.2 megabytes of memory (if monochrome). This memory in a printer isreferred to as a “buffer”. Memory is an expensive component, and it isan advantage to reduce the amount of memory required in a printerbuffer. In the past, this has been accomplished by applying a“compression algorithm” to the data in the buffer. Despite thesignificant compression which may arise from thresholding, furthercompression is desired.

[0016] There are currently compression schemes for single bit data. Someof these schemes work preferentially better on data that was originallytext and some work better on data that was originally an image. Some ofthese schemes include facsimile standards, such as the ITU standards,using Huffman encoded run lengths and the JBIG (Joint Bi-level ImageGroup) standard.

[0017] There are two distinct families of prior art compression schemes:lossy and lossless. Lossless compression guarantees that no data will belost upon a compression and decompression sequence. For example, onelossless compression scheme accomplishes this guarantee by searching thedata for any repeating sequences such as “001001001001001001”. Usingthis lossless compression scheme, the sequence “001” would be storedalong with the number of times it recurs—six. However, losslesscompression schemes may not provide a satisfactory level of compression,e.g., due to the absence of repeating sequences in the source data forthe above example. Nonetheless, due to its accuracy, losslesscompression is used when storing database records, spreadsheets, or wordprocessing files.

[0018] A lossy scheme achieves a greater level of compression whilerisking a loss of a certain amount of accuracy. However, certain typesof stored information do not require perfect accuracy, such as graphicsimages and digitized voice. As a result, lossy compression is oftenutilized on such types of information.

[0019] The most interesting prior art method is set forth in the JBIGstandard. Pixels are processed in the usual scan order, i.e., row_(i) isentirely processed before row_(i+1) and in each row, column_(i) precedescolumn_(i+1). Encoding the current pixel uses a context, which comprisesa set of nearby pixels that have already been encoded. If, e.g., tenpixels were used as a neighborhood, there would be 2¹⁰ possiblecontexts. Based on the frequency with which the current context has beenpreviously encountered, the encoder makes a prediction and estimates theprobability that the prediction is accurate. If the estimatedprobability is reliable and near to certainty, then an arithmeticentropy encoder can losslessly encode the prediction error (e.g., 0 forno error, 1 for error) with much less than 1 bit per pixel. The decoderhas the same context and frequency information, and is therefore able tointerpret the 0 or 1 to determine the true value of the pixel.

[0020] See also U.S. Pat. No. 5,442,458, issued to Rabbani et al., whichis directed to an encoding method for image bitplanes using conditioningcontexts based on pixels from the current and previous bitplanes.

SUMMARY OF THE INVENTION

[0021] The present invention provides a method and apparatus forcompression of data. Whereas the performance of compression schemes ofthe prior art are often dependent on the type of data being compressed,the invention provides for the application of a plurality of compressionschemes to the data such that improved compression ratios are achieved.A first embodiment provides for compression of each pixel by one of aplurality of different entropy-based compression schemes based upon aprobability cost analysis. A second embodiment provides for compressionof each pixel based on a hybrid context formed using a plurality ofcompression schemes for improved probability determination, and thusimproved entropy encoding.

[0022] The first embodiment of the invention provides a method forchoosing the most effective compression scheme per pixel. A multiplicityof compression schemes are utilized and a cost value is associated witheach scheme on a pixel by pixel basis. After associating a cost witheach scheme, the method selects between the most effective or lowestsummed cost scheme on a pixel by pixel basis. The selected schemeprovides a predicted value of the current pixel and an estimate of theprobability that the prediction is correct. The correctness of theestimate, either true or false, is then encoded by an entropy encoderwhich uses the estimated probability to encode the true or false outcomein less than one bit, provided that the estimated probability isaccurate and not in the vicinity of 0.5. Typically, the estimatedprobability is greater than 0.95. In a preferred embodiment, the entropyencoding is performed using an arithmetic encoding process.

[0023] In one specific embodiment, one of the compression schemesutilized is referred to as the “inverse” scheme. The inverse schemepredicts the gray value of a frame buffer pixel. The scheme examines aset of recently scanned pixels to define a range within which the pixelunder consideration is likely to fall. The range is determined asfollows.

[0024] For each previously scanned pixel, the thresholded value and theassociated threshold define a range. For example, if the threshold is150 and the thresholded value is 1, the pre-thresholded value is in therange of 150 to 255. If the thresholded value is 0, the pre-thresholdedvalue is in the range of 0 to 149. The resulting range is intersectedwith the similarly determined range from the next closest neighborpixel.

[0025] The intersecting of the threshold matrix ranges continues foreach previous neighbor pixel until all pixels have been analyzed oruntil there is a contradiction, namely that a range is encountered whichhas no common overlap with the most recently calculated range. A valuewithin the most recently calculated range is then selected as anestimate of the value of the pixel under consideration. The differencebetween the corresponding threshold value and the estimated value isthen calculated. Subsequently, a probability table is updated whichrecords the number of times a binary one (1) or zero (0) resulted withthat difference calculation. This probability table is used in theencoding stage.

[0026] A second scheme utilized in the specific embodiment above is onesimilar to that of JBIG, referred to as the “context” scheme. A set ofpixels in a frame buffer are selected. Subsequent to the pixel set'sthresholding, the thresholded values are concatenated to provide abinary number. A frequency table is maintained which records the numberof times a binary one (1) or a binary (0) occurs for each sequence ofbinary numbers for the pixel set. The concatenated binary number is usedas an index into the frequency table, from which the probabilities foruse in the encoding stage are derived.

[0027] In the second embodiment of the invention, a hybrid context isformed using a first number of bits of the hybrid context to storeprevious pixel information gathered using a first compression scheme,and using further portions of the hybrid context to store previous pixelinformation gathered using other compression schemes. Statistics arestored in a table indexed by the hybrid context, and entropy encoding isperformed based on the probability information in the table indexed bythe hybrid context for the current pixel. The combination of differentprobability determining schemes results in greater probability valuesfor each pixel, and correspondingly higher compression ratios.

[0028] In a further specific embodiment, a thirteen bit hybrid contextis formed using seven bits to store a quantized gray value differencedetermined using the inverse scheme, and using six bits to storerecently scanned pixel values in the neighborhood in accordance with thecontext (JBIG) scheme. A table, indexed by the hybrid context, is formedcontaining the probability for a given pixel, having the respectivesix-bit JBIG context and the respective seven-bit gray value difference,to be “0” or “I”. An entropy encoder encodes the pixel value based onthe prediction and the probability determined from the hybrid context.

BRIEF DESCRIPTION OF THE DRAWINGS

[0029]FIG. 1A is a sample table representing a frame buffer.

[0030]FIG. 1B is a sample table representing a threshold matrix.

[0031]FIG. 1C is a sample table representing the resulting pixel arrayfrom thresholding FIG. 1A with 1B.

[0032]FIG. 2A is a sample table representing a frame buffer with emptycells to be estimated by the present invention.

[0033]FIG. 2B is a sample table representing a threshold matrix which isutilized in predicting the empty cells of FIG. 2A.

[0034]FIG. 2C is a sample table representing the resulting pixel arraywhich is utilized in predicting the empty cells of FIG. 2A.

[0035]FIG. 3 is a sample probability table which is utilized in thecontext scheme to maintain statistics.

[0036]FIG. 4 is a flow diagram demonstrating the switching method of thepresent invention.

[0037]FIG. 5 is a flow diagram demonstrating the inverse scheme.

[0038]FIG. 6 is a flow diagram demonstrating the process of calculatingthe g-estimate of an interval.

[0039]FIG. 7 is a flow diagram demonstrating the context method.

[0040]FIG. 8 is an illustration of one embodiment of a hybrid context.

[0041]FIG. 9 is a flow diagram of an encoding process implementing ahybrid context.

[0042]FIG. 10 is a mapping diagram for difference values in oneembodiment of the invention.

[0043]FIG. 11 is a pixel diagram illustrating nearest neighbors for amodified JBIG scheme.

[0044]FIG. 12 is a threshold diagram for a multi-bit embodiment.

[0045]FIG. 13A is a block diagram of a switching embodiment of theinvention.

[0046]FIG. 13B is a block diagram of a hybrid context embodiment of theinvention.

DETAILED DESCRIPTION OF THE INVENTION

[0047] A method and apparatus for compression of data is described. Inthe following description numerous, specific details, such as the use ofthe context/JBIG and inverse schemes, are set forth in order to providea more thorough understanding of the present invention. It will beapparent, however, to one skilled in the art, that the present inventionmay be practiced without these specific details. In other instances,well known features have not been described in detail so as not tounnecessarily obscure the present invention.

[0048] Current compression methods are comprised of a modeling and anencoding stage. During the modeling stage, the probability that a pixelvalue will be a binary one (1) or zero (0) is estimated. During theencoding stage, this probability is utilized to compress or encode thepixels. A disadvantage associated with limiting the compression to onemodeling scheme is that some schemes work better on data that wasoriginally text and some work better on data that was originally animage.

[0049] The present invention overcomes this disadvantage by applying aplurality of different modeling schemes to each pixel. In oneembodiment, the least costly scheme in terms of bits is used to compressthe data. In a second embodiment, each scheme is reduced and combinedinto a single hybrid compression scheme having the advantages associatedwith each of its constituent schemes.

[0050] One embodiment of the invention, as illustrated in FIG. 4,provides a method of selectively switching between the most effectivecompression schemes on a pixel by pixel basis. The first step of theswitching method is that of choosing a multiplicity of compressionmodeling schemes which are going to be used 400. In one embodiment ofthe invention, a scheme similar to that of JBIG, referred to as thecontext scheme, is utilized as one of the schemes in the modeling stage,and the “inverse” scheme is utilized as another scheme in the modelingstage.

[0051] Prior to selecting a modeling scheme, a cost value is calculatedfor each scheme 404. Thus, the cost for the context scheme and the costfor the inverse scheme are calculated (see discussion below). The schemewith the lowest summed cost in a pixel neighborhood around the currentpixel is selected 406, and the current pixel is encoded using theselected scheme 408. Subsequent to the encoding, the next pixel to beencoded is selected, and the process is repeated. Such a calculation ofcosts and encoding for each pixel permits the most effective or lowestcost scheme to be utilized to encode each pixel independently.

[0052] In the above embodiment, the inverse scheme predicts the grayvalue of a frame buffer pixel. The inverse scheme, which is discussedmore fully below, computes a probability that the current pixel is a 0and a probability that it is a 1, the two probabilities summing to one.If either probability is high, i.e. close to-one, then much less thanone bit is required to encode the pixel bit, resulting in compression.

[0053] To establish the probability, the inverse scheme predicts thevalue of the current pixel by examining/analyzing its neighboringpixels. The threshold ranges of the neighboring pixels are intersecteduntil either all of the ranges have been intersected or the ranges ceaseto intersect. If a neighboring pixel range does not intersect with thepreviously intersected pixel ranges, the previously intersected pixelranges are used as the resulting range. A value within the resultingrange is selected and differenced with the threshold value for the pixelto be estimated. A table is then created which records the probabilitiesthat the true binary value will be a one (1) or a zero (0) based on thedifference value. The probability that a pixel will be a zero (0) or a(1) may be utilized in the encoding stage.

[0054] Additionally, in the above embodiment, a scheme similar to thatof JBIG, referred to as the “context” scheme, is utilized. A set ofpixels in a frame buffer are selected and thresholded. The thresholdedvalues are then concatenated to provide a binary number. A frequencytable is compiled which records the number of times a binary one (1) ora binary (0) occurs for each sequence of binary numbers. Theconcatenated binary number is used as an index into the frequency table.As a result, the frequency table maintains the probabilities which maybe utilized in the encoding stage. The values in the frequency table maybe scaled down at intervals to reduce the storage requirements of thetable.

[0055] Though various embodiments are described with reference to a“frequency” table, other means for estimating the probability of thecurrent context may be used to implement an embodiment of the invention.Typically, a numerical value representative of a statistical history ofa context is stored, though the extent of the history may vary fordifferent embodiments. The probability value and prediction aredeterminable from the numerical value representation, but need not beexplicitly present in the table. Further, the stored numerical value maybe updated (e.g., as a byproduct of an entropy encoding engine) witheach context occurrence by increasing or decreasing the respectivenumerical value based on the current pixel prediction and current actualpixel value.

INVERSE COMPRESSION SCHEME

[0056] The inverse scheme is a scheme which estimates the probabilityduring the modeling stage for later use in the encoding stage of thepresent invention. Referring to FIG. 4, the modeling stage includessteps 400, 402, and 404. The encoding stage includes steps 406 and 408.More specifically, the compression schemes are utilized after the pixel(p) has been selected 402 and before or as part of the calculation ofcosts 404. The inverse scheme is unique and novel in its approach toestimating the pixel value. The inverse scheme scans the pixel array(P[i][j]) row by row using information from previously scanned pixelsand the threshold array to predict the current pixel.

[0057] The estimate of the gray value G24 (FIG. 2A) and the thresholdvalue are then used to make a prediction, with a probability, as to thevalue B24. This is derived from the previous occurrences of thearithmetic difference of the gray estimate and the threshold value.

[0058] To perform the estimate, a small set of pixels (S) is utilized,near to P[i][j] that precedes P[i][j] in scan order. Thus, referring toFIG. 5, the first step is the selection of a pixel set 502. In thepresent example, the scan order is from left to right. Thus, the pixelsof FIG. 2C would be scanned in the following order: P₁₁, P₁₂, P₁₃, P₁₄,P₁₅, P₂₁, P₂₂, . . . , P₄₅, where P_(ij) represents i rows and jcolumns. Referring again to FIG. 2C, the S-set would likely consist ofthe values scanned prior to the relevant pixel and nearby. The relevantpixel is P₂₄ due to the fact that it corresponds to the location in theG-array being estimated (200). Thus, the S-set would contain: P₁₁ (0);P₁₂ (0); P₁₃ (1); P₁₄ (0); P₁₅ (0); P₂₁ (0); P₂₂ (0); and P₂₃ (1).

[0059] For each pixel P[i][j] in the S-set, an estimate of G[i][j] (thevalue of the pixel prior to thresholding) may be obtained by knowingwhat value t was used to threshold G[i][j]. In other words, an estimateof G₁₁ (of FIG. 2A) may be obtained by knowing that the value 128 (thevalue at T₁₁ of FIG. 2B) was used as the threshold to obtain a binary 0result (the value at P₁₁ of FIG. 2C). Similarly, an estimate of G₂₂ (ofFIG. 2A) may be obtained by knowing that the value 219 (the value at T₂₂of FIG. 2B) was used as the threshold to obtain a binary 0 result (thevalue at P₂₂ of FIG. 2C).

[0060] Referring to FIG. 5, after selecting a set of neighboring pixels502, a pixel that has not been previously selected (NP) is selected fromthe pixel set (S) 504. Referring to FIG. 2A, a pixel such as G₂₃ wouldbe selected to begin the estimation. If this is the first pixel to beselected 506, then a first interval level must be set. Setting the firstinterval level consists of first determining whether or not the binarythresholded value (BTV) of the pixel (NP) is equal to zero (0) or one(1) 508. If the binary thresholded value (BTV) is equal to zero (0),then the value of the pixel (NP) may be assumed to be lower than thethreshold level 510. Conversely, if the binary thresholded value (BTV)is equal to one (1), then the value of the pixel (NP) may be assumed tobe higher than or equal to the threshold level 512. Thus, assuming, asin the preferred embodiment, that the pixel values are made up of 8 bits(256 different values), the minimum value is that of zero (0) and themaximum value is that of 255.

[0061] The following equations set forth what the range of G[i][j] (NP)is depending on the resulting binary thresholded value (BTV):

[0062] t≦G[i][j]≦255, if the BTV of P[i][j]=1

[0063] 0≦G[i][j]≦t, if the BTV of P[i][j]=0

[0064] If the binary thresholded value (BTV) at P[i][j] is equal to 1,then it may be inferred that the value at G[i][j] is greater than orequal to the t-value which was used in G[i][j]'s (NP's) thresholding.Similarly, if the binary thresholded value (BTV) at P[i][j] is equal to0, then it may be inferred that the value at G[i][j] is less than thet-value which was used in G[i][j]'s thresholding.

[0065] For example, if the binary thresholded value (BTV) at P[i][j] wasequal to a binary 1 and the threshold level (T[i′][j′]) is equal to 200,then it may be inferred that the value at G[i][j] is equal to or greaterthan 200. Similarly, if P[i][j] is equal to a binary 0 and the thresholdvalue (T[i′][j′]) is equal to 200, then it may be inferred that thevalue at G[i][j] is less than 200. Referring to FIG. 2C, the binarythresholded value (BTV) at P₁₃ is 1. The value which was used as athreshold was 101 (the value at T₁₃ of FIG. 2B). As a result, it can beestimated that the value of G₁₃ (NP) of FIG. 2A is greater than or equalto 101. Similarly, the binary thresholded value of P₂₂ (of FIG. 2C) is0. The value which was used as a threshold for P₂₂ was 219 (the value atT₂₂ of FIG. 2B). Consequently, it may be inferred that the value at G₂₂(NP) is less than 219. Although the above examples of FIG. 2 demonstratethat the values of G₁₃ and G₂₂ are already known (147 and 205respectively), to utilize the inverse scheme of the present invention,estimates of all pixels in an S-set must be performed.

[0066] Based on the estimates of the surrounding pixels, the inversescheme estimates the desired value at G[i][j] (200). To make theestimation of X at G[i][j] (200), the intervals for each of the pixelsin S are intersected. Hence, referring again to FIG. 5, subsequent tothe first pixel 506, the intervals associated with the remaining pixels(NP) in the pixels set (S) are intersected. The intersections areperformed sequentially in order of proximity to pixel p. Thus, theintervals associated with the pixels from the S set are intersected oneat a time beginning with the pixel closest to pixel p. Referring to FIG.2A, if pixel X 200 is the pixel to be estimated and the first pixel tobe analyzed is that of G₂₃ (with a value of 234), the next pixel thatwould have been scanned is that of G₂₂ (with a value of 205). The nextpixel that would have been scanned is that of G₂₁, then G₁₅, etc.

[0067] Referring again to FIG. 5, the first step of intersecting is thatof determining the binary thresholded value of the pixel which iscurrently being analyzed/intersected 514. If the binary thresholdedvalue is zero (0), then once again, it is known that the value prior tothresholding was less than the threshold value (T). Hence, the maximumvalue of the pixel (NP) would be that of one less than the thresholdvalue. For example, the binary thresholded value of P₂₂ (NP) (of FIG.2C) is 0. The value which was used as a threshold for P₂₂ was 219 (thevalue at T₂₂ of FIG. 2B). Consequently, it may be inferred that thevalue at G₂₂ (NP) is less than 219 or the maximum value of NP is oneless than 219 or 218. Hence, NP has a range of from 0 to 218.

[0068] Similarly, if the binary thresholded value is equal to one (1),then once again, it is known that the value prior to thresholding wasgreater than or equal to the threshold value (T). Hence, the minimumvalue of the pixel (NP) would be that of the threshold value. Forexample, referring to FIG. 2C, the binary thresholded value (BTV) at P₁₃is 1. The value which was used as a threshold was 101 (the value at T₁₃of FIG. 2B). As a result, it can be estimated that the value of G₁₃ (NP)of FIG. 2A is greater than or equal to 101. Hence, the minimum value ofthe pixel (NP) would be that of 101.

[0069] If the intersection of the intervals as already determined doesnot intersect with the current NP's range, the process stops. As aresult, it must be determined if an intersection will occur at all(steps 516 and 518 of FIG. 5). If the existing interval level is greaterthan the threshold level, and the binary thresholded level was a zero(0), then the ranges do not intersect 516. For example, if the BTV iszero (0), the existing interval level is from 210 to 255, and thethreshold level is a 200, then the ranges 0-199 and 210-255 do notintersect. As such, the process stops without including the current NP'srange in the intersection.

[0070] Similarly, if the existing interval is less than the thresholdlevel, and the binary thresholded level was a one (1), then the rangesdo not intersect 518. For example, if the BTV is one (1), the existinginterval level is from 0 to 150, and the threshold level is a 200, thenthe ranges 0-150 and 200-255 do not intersect. As such the processstops. On the other hand, assuming that an intersection will occur, thenthe existing interval level is updated, restricting the interval to therange of the intersection (Steps 520, 522, and 524 of FIG. 5). Forexample, if the range for some pixel A (a pixel in closest proximity topixel p) was greater than or equal to 200 (200-255), and the range forsome other pixel B (the pixel in next closest proximity to pixel p) wasless than 210 (0-210), the intersection of the two intervals is from 200to 210.

[0071] The intersection of the ranges in close proximity to pixel p thencontinues. Continuing with the above example, the intersection 200-210would then be intersected with the next previous pixel in the scan.Referring to FIG. 2, assuming that the S-set consists of the nearest 7pixels as discussed supra, to estimate the value of X 200, the intervalsfor the pixels in the S-set (those in closest proximity to X) areestimated and intersected. Thus, the first pixel to be estimated is thatof G_(23.) To estimate what G₂₃ would be, its binary thresholded value(BTV) and its threshold value are examined. The binary thresholded value(BTV) of P₂₃ is 1 and the threshold value is 197. Thus, it may beestimated that G₂₃ must be greater than or equal to 197. Due to the factthat the pixels in FIG. 2 are made up of 8 bits, the maximum value is255. Hence, the interval for G₂₃ is from 197-255.

[0072] The next pixel in closest proximity is that of G₂₂. The binarythresholded value (BTV) of P₂₂ is 0 and the corresponding thresholdlevel at T₂₂ is 219. Therefore, the estimated value for G₂₂ must belower than 219. The intersection of the intervals from G₂₃ and G₂₂ isthen calculated. G₂₂ ranges from 0 to 218 and G₂₃ ranges from 197-255.Therefore, the intersection must be lower than 218 but higher than 197.Such an intersection results in an interval from 197-218. This processis then repeated with the next pixel in the closest proximity to X 200.

[0073] The intersection of the intervals continues until one of twoconditions has been met. The first condition occurs when all of theintersects of pixels in the S-set have been intersected (“Condition A”)(526). The second condition occurs when the intersection results in anempty set (i.e. the threshold intervals did not intersect) (“ConditionB”) (516 and 518), in which case the previous non-empty intersection isexamined.

[0074] Continuing with the example above, the next closest pixel is thatof G₂₁. The binary thresholded value (BTV) at P₂₁ is 0 and the thresholdlevel at T₂₁ is 111. Thus, the value of G₂₁ must be less than 111. Theintersection of this interval with the above interval (197-218) resultsin a set which is between 0 and 111 and also between 197-218. Due to thefact that no such value exists, the two intervals do not intersectresulting in a “contradiction”. As a result, “Condition B” has been met(the threshold intervals did not intersect). The intersection of theintervals process comes to a halt. The last intersection whichmaintained a value is preserved (197-218).

[0075] From the resulting intersection interval, a value is estimated(g-estimate) and selected for G[i][j] (pixel p). Referring to FIG. 6, if“Condition A” has been met 602A, then the midpoint of the resultingintersection is used as the g-estimate 604. Thus, if all pixels areintersected, condition A is met and the midpoint is used. In the aboveexample, if no contradiction had resulted and all of the pixel intervalshad been intersected, the midpoint between 197 and 218 (the value 208)would be used as the g-estimate. If “Condition B” has been met 602B,then the value closest to the contradiction is utilized (Steps 606, 608,and 610). Thus, if pixel intervals do not intersect, condition B is metand an endpoint is used.

[0076] In the above example, the resulting intersection interval is from197-218. Further, the contradiction and halting arose with a value of111 (Step 606A of FIG. 6). Therefore, the value closest to thecontradiction, yet still within the interval is that of 197, which isthen used as the g-estimate 608. If the contradiction had occurred witha non intersecting interval of 230-255 (Step 606B of FIG. 6), then theendpoint of 218 would be used as the g-estimate because it is theclosest value to the contradiction (230) (Step 610 of FIG. 6).

[0077] The first step in estimating the current pixel probability isobtaining/computing a difference value. The difference value (diff) isthe difference between the g-estimate for pixel p and the thresholdvalue (T) for pixel p. Thus, diff equals the g-estimate minus T[i′][j′]where T[i′][j′] is the threshold value for the pixel at P[ij]:

diff=g-estimate−T[i′][j′]

[0078] Once again continuing with the above example, the value 197 isthe g-estimate. Diff is therefore equal to 197−T[i′][j′]. T[i′][j′] inthe present example is equal to 214 (the value at T₂₄ 220). Thus, diffis equal to 197−214 or −17.

[0079] The value of diff is used as the context for obtaining anestimated probability from a table comprising statistical historyinformation for each context. For eight-bit g-estimates and thresholdvalues, diff may retain values in the range: −255, −254, . . . , 253,254.

[0080] (g values in 0, 1, . . . 255

[0081] t values in 1, . . . , 255)

[0082] The current pixel bit value and the associated diff value contextmay be used to update the statistical information in the table.

[0083] In one embodiment, statistics are maintained on the approximatenumber of times previously for each diff value that P[i][j] has resultedin a binary 0 after thresholding and the number of times P[i][j] hasresulted in a binary 1 after thresholding. Thus, a table indexed by thediff value context may be created which maintains approximatestatistical information gathered over a number of past pixels.

[0084] For example, if for seven out of 10 times when the diff value wasa −4, P₁₂ was a 0, and for three out of those ten times P₁₂ was a 1,such frequencies/statistics or approximations thereof would be recorded.Based on this frequency, prob₁ may be estimated. Prob₁ is equal to theestimated probability that the pixel is a binary 1. Therefore, as in theabove example, if for the last three out of ten times when the diffvalue was a −4, prob₁ would retain the value of approximately {fraction(3/10)} or 0.3. Prob₀ is equal to the estimated probability that thepixel is a binary 0. Similarly, if for the seven of the last ten timeswhen the diff value was a −4, P₁₂ was a 0, prob₀ would retain the valueof approximately {fraction (7/10)} or 0.7. It should be noted that thetotal of the probabilities is 1:

prob₀+prob₁=1

{fraction (7/10)}+{fraction (3/10)}=1.

[0085] Thus, both probabilities need not be estimated in allembodiments, as one probability may be determined from the other.

[0086] As previously stated, the “frequency” table implementation forestimating probabilities is one example of how probability informationmay be determined for each context. Other methods for estimating theprobability associated with each diff value context may also be usedwithin the scope of the invention.

CONTEXT COMPRESSION SCHEME

[0087] A second scheme used in some embodiments of the invention is avariation of the JBIG scheme described above. Referring to FIG. 7, thepixels in S or a similar set are utilized (802). The binary thresholdedvalues (BTV) are concatenated to provide a binary number which is thenused as an index into a table of frequency counts (804). The estimatedprobability table is compiled from each previous occurrence of the index(context) (806). This method is referred to as the context method.Hence, if the context is from 4 pixels, a table such as in FIG. 3 ismaintained and utilized to retain statistics of prob₁ or prob₀ in thecontext/JBIG scheme.

[0088] Referring to the table, the probability that the next bit after1011 would be a 1 is examined by looking to the appropriate location ofthe table at 1011 signified by 300. Thus, the table indicates that{fraction (4/10)} or 4 out of the last 10 times, the next bit was a 1.Similarly, the probability that the next bit after 1101 would be a 1 isexamined by looking to the appropriate location of the table at 1101.Thus, the table indicates that {fraction (8/13)} or 8 out of the last 13times, the next bit was a 1. The table may also contain approximationsrather than exact values. After each pixel is encoded, the table isupdated to record the appropriate statistics.

SWITCHING METHOD

[0089] The generation of a context (e.g., a diff value or a JBIG-typecontext) and assigning of a probability to the context is the modelingportion of the compression. Thus, the inverse scheme and context schemecomprise the modeling portion of an embodiment of the invention. If theprobabilities are accurate and close to 1, high compression is achieved.In other words, the more accurate the probabilities are and closer to 1(or 10 out of 10 times; or 7/7 times . . . ), the higher thecompression.

[0090] In some embodiments, an entropy encoder may update the predictionand probability data in a feedback arrangement. Modeling may thus beperformed during the encoding process by an adaptive encoder. Forexample, if a certain context and bit value are occurring with greaterfrequency, the estimated probability for that context may be adjustedupwards if the prediction matches the actual bit value, or downwards ifthe prediction does not match the actual bit value.

[0091] The portion of compression which involves conversion of theprediction, the estimated probability, and the actual bit value intoencoded bits is called entropy encoding. Entropy is a term of art whichmeans or is a measure of how much information is encoded in a symbol.Thus, the higher the entropy of a message, the more information itcontains. In this respect, if one uses entropy encoding, bits of datamay be encoded using a number of bits corresponding to their informationcontent. Very predictable bits have a lower entropy, so require fewerbits to encode.

[0092] As the probability of a certain bit increases, the compressionobtained using entropy encoding increases. Thus, the objective is to usea scheme which results in the highest probability for each pixel.Therefore, the best possible entropy encoding would use the highestprobability as obtained from various different schemes (e.g., theinverse scheme, the JBIG scheme, etc.). The switching method of thepresent invention allows for bit-level selective switching from schemeto scheme to utilize the highest probability.

[0093] The information regarding the pixels prior to P[i][j] (and thethreshold array) is referred to as the context:${{P\lbrack i\rbrack}\lbrack j\rbrack} = \left\{ \begin{matrix}{{{prediction} = 1},{{{with}\quad {estimated}\quad {probability}} = {prob}_{1}}} \\{{{prediction} = 0},{{{with}\quad {estimated}\quad {probability}} = {{1 - {prob}_{1}} = {prob}_{0}}}}\end{matrix} \right.$

[0094] In this respect, the probability that P[i][j] is equal to 1 isprob₁ and the probability that P[i][j] is equal to 0 is prob₀. Thus,using the context scheme and referring to FIG. 3, the estimatedprobability, probe, that P[i][j] will have a binary value of 1 (300) isapproximately {fraction (4/10)} or 0.4 and the estimated probability,prob₀, that P[i][j] will have a binary value of 0 is approximately

[0095] 1-prob₁ or 1-0.4=0.6 or {fraction (6/10)}.

[0096] Using arithmetic encoding (a type of entropy encoding), thehigher the probability, the higher the compression capability. In orderto determine the number of bits which are required to encode a set ofbinary numbers, the probability is used in a logarithmic calculation.More specifically, the number of bits required to encode a binary numberwith a known probability is:${{\log \quad}_{2}\frac{1}{{prob}_{1}}\quad {if}\quad {the}\quad {outcome}\quad {{P\lbrack i\rbrack}\lbrack j\rbrack}} = {1\quad {and}}$${{\log \quad}_{2}\frac{1}{1 - {prob}_{1}}\quad {if}\quad {the}\quad {outcome}\quad {{P\lbrack i\rbrack}\lbrack j\rbrack}} = 0.$

[0097] Thus, compression will take place according to the abovestatistics using arithmetic encoding.

[0098] If prob₁ is an accurate reflection of the true probability, theexpected cost in encoding bits to encode P[i][j] is given by:

−(prob₀) log₂ prob₀−prob₁ log₂ prob₁=−(1-prob₁) log₂ (1-prob₁)−prob₁log₂ prob₁

[0099] To keep this cost low, the estimate of prob₁ needs to be accurateand as close to 0 or 1 as possible. As the estimate of prob₁ moves awayfrom 0.5, the number of bits required to encode the respective pixel bitdecreases. This results due to the fact that if prob₁ is near 0 (i.e.,prob₀ is near 1), then the number of bits required to encode that bit isclose to 0. Similarly, if prob₁ is near 1, then the number of bitsrequired to encode that bit is also close to 0. Thus, the closer theprobability is to 0 or 1, the lower the cost of encoding is.

[0100] The probability prob, is a conditional probability, conditionedon the context used. In the embodiment described herein, two differentcontexts (schemes) are utilized and whichever context (scheme) resultsin the lowest total cost over a set of previously encoded pixels is thescheme used for encoding the current bit. In other embodiments, morethan two schemes may be cost-evaluated for encoding each pixel bit.

[0101] At each previously scanned pixel, the cost to encode that pixelis computed as:

[0102] −log₂ prob₁ ^(inverse) for the inverse scheme, and

[0103] −log₂ prob₁ ^(context) for the context scheme

[0104] if the pixel was a one. Similarly, −log₂ prob₀ ^(inverse) and−log₂ prob₀ ^(context) if the pixel was a zero, when prob_(i) ^(inverse)and prob_(i) ^(context) are the probability estimates from the inverseand context schemes.

[0105] The next step is to add up the cost for the set of previouslyencoded pixels, such as S, for each scheme. The scheme with the lowersum is used to predict P[i] [j]. In other words, the scheme with thelower summed cost is utilized for the encoding. Thus, if the summed costof the inverse scheme over the pixel set S is 140 bits and the summedcost of the context scheme over the pixel set S is 165 bits, then theinverse scheme would be utilized for the encoding. The summed cost isrecalculated for each new pixel scanned in the P[i][j] array. Hence, thescheme used may be switched from pixel to pixel depending on the costassociated with each scheme.

[0106]FIG. 13A is a functional block diagram illustrating a switchingembodiment of the invention. In FIG. 13A, scanned data is stored inregisters (e.g., a shift register) or memory cells 1500 for use inencoding the data. The neighboring pixel bit values 1505 of the set Sfrom registers 1500 are provided to the multi-scheme context/indexgenerator 1501. Contexts or indices 1506 are generated for each schemeusing methods such as those described for the inverse and JBIG schemes.

[0107] Contexts and indices (such as diff and the JBIG context) 1506 arepresented to the statistics/probability tables 1502 to access therespective stored predictions and probabilities 1507 for each scheme.The prediction/probability values 1507 are provided to the cost analysisswitcher/selector 1503 for determination of the current encoding scheme,based on the cost analysis described above. The prediction/probability1508 for the selected scheme is then provided to entropy encoding engine1504. The current pixel bit value 1509 from registers 1500 is alsoprovided to entropy encoding engine 1504, and based on the value ofprediction/probability 1508, entropy encoding engine 1504 producesencoded data 1510.

[0108] The functional blocks of FIG. 13A may be embodied in dedicatedelectronic hardware, or they may be embodied in software functionsimplemented in general electronic hardware, or they may be embodied in acombination of dedicated hardware and software functions.

HYBRID CONTEXT METHOD

[0109] A second embodiment of the invention utilizes multiplecompression schemes to form a hybrid context for each pixel. By using ahybrid context, the embodiment is able to take advantage of the uniquestatistical aspects of each compression scheme in determining theprobability for each possible hybrid context. The resulting hybridcontext can provide improved prediction ability (i.e., higherprobabilities) with correspondingly higher compression ratios.

[0110] The hybrid context is formed by assigning a portion of bits inthe context to each compression scheme. The size of the total contextand the apportionment of the bits between the respective schemes mayvary for different embodiments. For the purpose of clarity, a specificembodiment having a two-scheme thirteen-bit context is described.

[0111] In this embodiment, the thirteen-bit context is separated into aseven-bit portion assigned to the inverse scheme, and a six-bit portionassigned to an abbreviated JBIG scheme. This apportionment isillustrated in FIG. 8. As shown, the six least significant bits (B6-B1)of the thirteen-bit context store the JBIG context information, and theseven most significant bits (D6-D0) store the inverse schemeinformation. Similar embodiments may have a different ordering of thiscontext information.

[0112] The set of previous pixels S′ is a reduced set from S describedearlier. The set S′ consists of six previous pixel values as shown inFIG. 11. B0 represents the current pixel, whereas B1-B6 represent thesix nearest neighbors, with B1 being the nearest neighbor, B2 being thesecond nearest neighbor, etc. The values of B1-B6 provide theabbreviated JBIG context portion for the hybrid context.

[0113] With respect to the inverse scheme context portion, the “grayvalue” estimation is performed as described previously for the inversescheme by progressing through the respective ranges of the previouspixel values, preferably in the order of B1, B2, B3, etc., to maintainthe priority of the nearest pixels since the nearest pixels contain thehighest predictive information. In other embodiments, to reduce theamount of calculation per pixel, the “gray value” range for severalpixels may be precalculated by column and stored to render repeatedcalculation of the intersections unnecessary. The calculation reductionis achieved with some compromise in priority of the pixel information.

[0114] The resulting difference value (diff) between the gray valueestimate and the current pixel threshold is typically within the rangeof −255 to 254, e.g., for eight-bit pixel data. In order to reduce thisdifference value into the prescribed seven bits, the difference value isremapped into the range of 0 to 127. One such mapping is illustrated inFIG. 10.

[0115] In FIG. 10, the difference value (diff) is mapped into the sevenbit difference value (diff′) for generation of the inverse schemeportion of the hybrid context as follows:${diff}^{\quad \prime} = \left\{ \begin{matrix}{0,} & {{{for}\quad {diff}} < {- 64}} \\{{{diff} + 64},} & {{{for} - 64} \leq {diff} \leq 63} \\{127,} & {{{for}\quad {diff}} > 63}\end{matrix} \right.$

[0116] The above distribution for diff′ assures better probabilityresolution for gray value estimates near the threshold value at the costof clamping diff′ for gray value estimates further away from thethreshold, where the probability is less likely to vary substantiallyfor different diff values.

[0117] With the hybrid context formed as described, statistical analysisof a set of past data may be performed to establish a probability tableindexed by specific context values for use in the entropy encoding. Asdescribed previously, this may be done by tracking the number ofoccurrences of each particular context, and the number of times eachparticular context resulted in a “I” or a “0.” The resulting probabilityfor a particular context to yield a “1,” for example, would then be anapproximate count of times that particular context produced a “1”divided by the overall approximate count for occurrences of thatparticular context. Also, as mentioned previously, an adaptive entropyencoder may update statistics during encoding to maintain probabilitydata, or some combination of statistical analysis and adaptive encodingmay be used.

[0118]FIG. 9 is a flow diagram for the encoding process using the hybridcontext. In step 1100, the six-bit JBIG context is determined from sixprevious pixels. In step 1101, the seven-bit inverse scheme context(diff′) is determined. The relative order in which steps 1100 and 1101are performed is not critical to the operation of the embodiment. Instep 1102, the two context portions are combined into a single hybridcontext, and, in subsequent step 1103, the context is used as an indexinto the statistics table to obtain the prediction and estimatedprobability for that context. In step 1104, the prediction, estimatedprobability and actual current bit value are provided to an entropyencoder for encoding of the current bit.

[0119] On the decoding side, an entropy decoder will receive the encodedbit. By performing similar operations to steps 1100-1104, the hybridcontext is formed and applied to the same or a similar statistics tableto obtain the prediction and probability. The entropy decoder is thusable to decode the current bit value.

[0120]FIG. 13B is a functional block diagram illustrating a hybridcontext embodiment of the invention. In FIG. 13B, scanned data is storedin registers (e.g., a shift register) or memory cells 1500 for use inencoding the data. The neighboring pixel bit values 1505 (e.g., from theset S or S′) from registers 1500 are provided to the multi-schemecontext/index generator 1501. Contexts or indices 1506 are generated foreach scheme using methods such as those described for the inverse andJBIG schemes.

[0121] Contexts and indices (such as diff or diff′ and the JBIG context)1506 are provided to hybrid context generator 1511 to be combined intohybrid context 1512. Hybrid context 1512 is presented to thestatistics/probability table 1502 to access the respective storedprediction and probability 1508 for the hybrid context scheme. Theprediction/probability 1508 for the current hybrid context is thenprovided to entropy encoding engine 1504. The current pixel bit value1509 from registers 1500 is also provided to engine 1504, and based onthe value of prediction/probability 1508, engine 1504 produces encodeddata 1510.

[0122] The functional blocks of FIG. 13B may be embodied in dedicatedelectronic hardware, or they may be embodied in software functionsimplemented in general electronic hardware, or they may be embodied in acombination of dedicated hardware and software functions.

ENTROPY/ARITHMETIC ENCODING

[0123] The present invention permits the selective switching ofcompression schemes based on cost analysis, or the combining ofcompression schemes in a hybrid context. The objective is to representthe pixel array in fewer bits than n rows by m columns.

[0124] The encoding stage of the invention utilizes the probabilitiesobtained in the modeling stage to encode the bits such that they arerepresented in fewer bits. This is performed through entropy encoding.In an embodiment of the present invention, the method of arithmeticencoding is utilized to perform entropy encoding.

[0125] The above description has focused on the compression of imagedata compressed (thresholded) into one-bit data which is then furthercompressed by the methods of the invention. It will be obvious to thoseskilled in the art that the methods of the invention may be similarlyapplied to multi-bit data. For example, data may be thresholded as shownin FIG. 12 such that two-bit data is the result. Rather than onethreshold value for each pixel, three threshold values are provided foreach pixel to divide the initial pixel value range into four sections,each section represented by a two bit value (00, 01, 10, 11).

[0126] Multi-bit schemes may be encoded on a bit by bit basis. Bitwiseencoding may be performed by designating bit-planes for the data, suchas a most significant bit-plane and least significant bit-plane. Eachbit plane is then encoded using the bi-level data schemes describedabove, though lesser bit-planes may take advantage of the predictiveinformation in the more significant bits by using nearest neighbor setsincluding bits in adjacent bit-planes.

[0127] Magnitude code representations may be used to permit encoding ofsubsequent bits based on the encoding of the previously encoded bits ofa pixel. For example, if the three-bit magnitude code values 000, 001,011 and 111 are assigned to the two-bit pixel values 00, 01, 10 and 11,then the second bit need be encoded only if the most significant bit isa zero, and likewise, the least significant bit need be encoded only ifthe second bit is zero. Thus, multi-bit compression may be performedusing the methods of the present invention.

[0128] Thus a method and apparatus for data compression has beendescribed in conjunction with one or more specific embodiments. Theinvention is defined by the claims and their full scope of equivalents.

1. A method for compressing data in a computer system, the methodcomprising: providing a plurality of modeling schemes; calculating anestimated cost to encode a previous set of pixels for each modelingscheme; selecting a lowest cost scheme from the plurality of modelingschemes; and encoding the pixel based on the lowest cost scheme.
 2. Themethod of claim 1, wherein two modeling schemes are provided.
 3. Themethod of claim 1, wherein one of the modeling schemes is a contextscheme.
 4. The method of claim 3, wherein calculating comprises:calculating a probability that a pixel bit value is 0; and determining anumber of bits based on the probability.
 5. The method of claim 4,wherein for each pixel P_(ij) in the previous set, the encoding cost forthe context scheme is approximately equal to: −log prob₁ ^(ijj, context)if the pixel is a 1 else −log prob₀ ^(iji, context) if the pixel is a 0where prob₁ ^(i, j, inverse) is the estimate derived from previousoccurrences of P_(ij)'s context; where prob₁ ^(i, j, inverse)=1-prob₀^(i, j, inverse).
 6. The method of claim 1, wherein the encoding stepcomprises arithmetic encoding.
 7. Apparatus for compressing data in acomputer system, the apparatus comprising: means for calculating anestimated cost to compress a previous set of pixels for each one of aplurality of modeling schemes; means for selecting a lowest cost scheme;and means for encoding the pixel based on a selected scheme.
 8. Theapparatus of claim 7, wherein the plurality of modeling schemes comprisetwo modeling schemes.
 9. The apparatus of claim 7, wherein one of themodeling schemes is a context scheme.
 10. The apparatus of claim 7,wherein the means for calculating further comprises: means forcalculating a probability that a bit value is 1; and means fordetermining a number of bits based on the probability.
 11. The apparatusof claim 7, wherein the means for encoding comprises an arithmeticencoder.
 12. Apparatus for compressing data in a computer system, theapparatus comprising: a plurality of pixel values stored in memory; acontext generator receiving a set of pixel values from the memory, theset of pixel values comprising pixel values adjacent a current pixelvalue, the generator providing a plurality of contexts associated with aplurality of compression schemes; tables indexed by the plurality ofcontexts, the tables having statistical information; cost-based selectorreceiving the statistical information from the tables and providingstatistical information associated with a lowest cost compressionscheme; and an encoding engine receiving the current pixel value fromthe memory and the statistical information from the cost-based selector,the encoding engine providing encoded output.
 13. The apparatus of claim12, wherein the encoding engine comprises an arithmetic encoder.
 14. Theapparatus of claim 12, wherein the statistical information comprises aprediction and a probability value associated with each context.
 15. Theapparatus of claim 12, wherein the cost-based selector comprises: meansfor calculating a cost based on a probability value; and means forselecting a lowest cost scheme.